﻿using FileTransferProtocol;
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace TestReceiver
{
    public class FileSaver : IFileSaver
    {
        private string FileName { get; set; }

        private Stream Stream { get; set; }

        public Stream GetFileStream()
        {
            if (Stream != null)
                return Stream;

            if (string.IsNullOrEmpty(FileName))
                throw new Exception("文件名不能为空");

            if (!Directory.Exists("Upload"))
                Directory.CreateDirectory("Upload");

            //Stream = new FileStream(Path.Combine("Upload", Guid.NewGuid().ToString("N") + FileName), FileMode.CreateNew);
            Stream = new FileStream(Path.Combine("Upload", FileName), FileMode.CreateNew);
            return Stream;
        }

        public void SetFileName(string filename)
        {
            FileName = filename;
        }

        public string GetFileFullPath()
        {
            return Path.GetFullPath(Path.Combine("Upload", FileName));
        }
    }
}
